package com.ailk.tcm.hffw.android.common.network;

import net.tsz.afinal.http.AjaxCallBack;

public abstract class OnResponseListener extends AjaxCallBack<String> {

	@Override
	public void onFailure(Throwable t, int errorNo, String strMsg) {
		ResponseObject responseObject = new ResponseObject();
		responseObject.setSuccess(false);
		switch (errorNo / 100) {
		case 0:
			responseObject.setMessage("您的网络可能有问题");
			break;
		case 3:
			responseObject.setMessage("请求被重定向");
			break;
		case 4:
			if (errorNo == 404) {
				responseObject.setMessage("找不到请求地址");
			} else if (errorNo == 408) {
				responseObject.setMessage("您的网络可能有问题");
			} else {
				responseObject.setMessage("发送请求出错");
			}
			break;

		case 5:
			responseObject.setMessage("服务器错误");
			break;
		default:
			responseObject.setMessage("未知错误");
			break;
		}
		onResponse(responseObject);
	}

	@Override
	public void onSuccess(String t) {
		onResponse(new ResponseObject(t));
	}

	public abstract void onResponse(ResponseObject responseObject);
}
